<?php
	require_once("pre.php");
	require_once("auth.php");
?>
<?php if(! est_autorise("acces_commandes")) exit; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php require_once("title.php"); ?>
<?php
	require_once("../classes/Commande.class.php");
	require_once("../classes/Devise.class.php");
	require_once("../classes/Client.class.php");
	require_once("../classes/Paysdesc.class.php");
	require_once("../classes/Venteprod.class.php");
	require_once("../classes/Venteadr.class.php");
	require_once("../classes/Statut.class.php");
	require_once("../classes/Rubrique.class.php");
	require_once("../classes/Promo.class.php");
	require_once("../classes/Promoutil.class.php");
	require_once("../fonctions/divers.php");

	if(!isset($action)) $action="";
	if(!isset($statutch)) $statutch="";

?>

<?php
	$commande = new Commande();
	$commande->charger_ref($ref);
	$modules = new Modules();
	$modules->charger_id($commande->paiement);

	$devise = new Devise();
	$devise->charger($commande->devise);

?>

<?php

        if($statutch){
                $commande->statut = $statutch;


                if($statutch == 2 && $commande->facture == 0)
                	$commande->genfact();

				else if($statutch == 4 && $commande->datelivraison == "0000-00-00")
					$commande->datelivraison = date("Y-m-d");

                $commande->maj();

				ActionsModules::instance()->appel_module("statut", $commande);

        }

    if(isset($colis) && $colis != ""){
		$commande->colis = $colis;
		$commande->maj();
		ActionsModules::instance()->appel_module("statut", $commande);

	}

?>

</head>

<body>

<div id="wrapper">
<div id="subwrapper">

<?php
	$menu="commande";
	require_once("entete.php");
?>

<div id="contenu_int">
    <p><a href="accueil.php" class="lien04"><?php echo trad('Accueil'); ?> </a><img src="gfx/suivant.gif" width="12" height="9" border="0" /><a href="commande.php" class="lien04"><?php echo trad('Gestion_commandes'); ?></a></p>

<!-- Début de la colonne de gauche -->
<div id="bloc_description">
<div class="entete_liste_client">
	<div class="titre"><?php echo trad('INFO_COMMANDE'); ?></div>
</div>
<ul class="Nav_bloc_description">
		<li style="width:400px;"><?php echo trad('Designation'); ?></li>
		<li style="width:80px; border-left:1px solid #96A8B5;"><?php echo trad('Prix_unitaire'); ?></li>
		<li style="width:30px; border-left:1px solid #96A8B5;"><?php echo trad('Qte'); ?></li>
		<li style="border-left:1px solid #96A8B5;"><?php echo trad('Total'); ?></li>
</ul>

  <?php

	$venteprod = new Venteprod();

  	$query = "select * from $venteprod->table where commande='$commande->id'";
  	$resul = mysql_query($query, $venteprod->link);

  	$i=0;

  	while($row = mysql_fetch_object($resul)){

  	$venteprod->charger($row->id);

  	$produit = new Produit();
  	$produitdesc = new Produitdesc();

  	$produit->charger($venteprod->ref);
  	$produitdesc->charger($produit->id);

  	$rubrique = new Rubrique();
  	$rubrique->charger($produit->rubrique);

  	$rubriquedesc = new Rubriquedesc();
  	$rubriquedesc->charger($rubrique->id);

  	if($rubriquedesc->titre !="") $titrerub = $rubriquedesc->titre;
  	else $titrerub = "//";

  		if(!($i%2)) $fond="ligne_fonce_BlocDescription";
  		else $fond="ligne_claire_BlocDescription";
  		$i++;

  ?>
    <ul class="<?php echo($fond); ?>">
		<li style="width:392px;"><?php echo $venteprod->ref . " - " . $titrerub; ?> - <?php echo(str_replace("\n", "<br />", $venteprod->titre)); ?></li>
		<li style="width:73px;"><?php echo(round($venteprod->prixu, 2)); ?></li>
		<li style="width:23px;"><?php echo($venteprod->quantite); ?></li>
		<li style="width:20px;"><?php echo(round($venteprod->quantite*$venteprod->prixu, 2)); ?></li>
    </ul>

 <?php } ?>

 <?php

  		$client = new Client();
  		$client->charger_id($commande->client);

 		$venteprod = new Venteprod();

   		$query2 = "SELECT sum(prixu*quantite) as total FROM $venteprod->table where commande='$commande->id'";
  		$resul2 = mysql_query($query2, $venteprod->link);
  		$total = mysql_result($resul2, 0, "total");

  		$totalremise = $total - $commande->remise;

  		$port = $commande->port;
  		if($port<0) $port=0;

  		$statutdesc = new Statutdesc();
  		$statutdesc->charger($commande->statut);

  		$dateaff = substr($commande->date, 8, 2) . "/" . substr($commande->date, 5, 2) . "/" . substr($commande->date, 2, 2);
  		$heureaff =  substr($commande->date, 11);

 ?>
 <ul class="ligne_total_BlocDescription">
 	<li style="width:392px;"><?php echo trad('Total'); ?></li>
 	<li><?php echo(round($total, 2)); ?> <?php echo $devise->symbole; ?></li>
 </ul>
<div class="bordure_bottom" style="margin:0 0 10px 0;">
<div class="entete_liste_client">
	<div class="titre"><?php echo trad('INFO_FACTURE'); ?></div>
</div>
<ul class="Nav_bloc_description">
		<li style="width:60px;"><?php echo trad('Num_Fact'); ?></li>
		<li style="width:240px; border-left:1px solid #96A8B5;"><?php echo trad('Societe'); ?></li>
		<li style="width:150px; border-left:1px solid #96A8B5;"><?php echo trad('Nom'); ?> &amp; <?php echo trad('Prenom'); ?></li>
		<li style="border-left:1px solid #96A8B5;"><?php echo trad('Date_Heure'); ?></li>
</ul>
<ul class="ligne_claire_BlocDescription">
		<li style="width:59px;"><?php echo($commande->facture); ?></li>
		<li style="width:240px;"><?php echo($client->entreprise); ?></li>
		<li style="width:150px;"><a href="client_visualiser.php?ref=<?php echo($client->ref); ?>"><?php echo($client->nom); ?> <?php echo($client->prenom); ?></a></li>
		<li><?php echo($dateaff . " " . $heureaff); ?></li>
</ul>
</div>

<?php
	$moduletransport = new Modules();
	$moduletransport->charger_id($commande->transport);

	$moduletransportdesc = new Modulesdesc();
	$moduletransportdesc->charger($moduletransport->nom);
?>

<div class="bordure_bottom" style="margin:0 0 10px 0;">
	<div class="entete_liste_client">
		<div class="titre"><?php echo trad('INFO_TRANSPORT'); ?></div>
	</div>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Mode_transport'); ?></li>
		<li><?php echo $moduletransportdesc->titre; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Description'); ?></li>
		<li><?php echo $moduletransportdesc->description; ?></li>
	</ul>
</div>

<div class="bordure_bottom" style="margin:0 0 10px 0;">
<div class="entete_liste_client">
	<div class="titre"><?php echo trad('INFO_REGLEMENT'); ?></div>
</div>
	<ul class="ligne_claire_BlocDescription" style="background-image: url(gfx/degrade_ligne1.png); background-repeat: repeat-x;">
		<li class="designation" style="width:290px; background-image: url(gfx/degrade_ligne1.png); background-repeat: repeat-x;">Type de règlement</li>
		<li><?php
			try {
				$tmpobj = ActionsAdminModules::instance()->instancier($modules->nom);
				echo $tmpobj->getTitre();
			} catch (Exception $ex) {
				echo trad('Inconnu');
			}
	     ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Ref_transaction'); ?></li>
		<li><?php echo($commande->transaction); ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Total_commande_avant_remise'); ?></li>
		<li><?php echo(round($total, 2)); ?> <?php echo $devise->symbole; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Remise'); ?></li>
		<li><?php echo(round($commande->remise, 2)); ?> <?php echo $devise->symbole; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Code_promo'); ?></li>
		<li><?php
		$promoutil = new Promoutil();
		if($promoutil->charger_commande($commande->id)){
			$promo = new Promo();
			$promo->charger_id($promoutil->promo);
			?>
			<a href="promo_modifier.php?id=<?php echo $promo->id; ?>"><?php echo $promo->code; ?></a>
			<?php
		}
		?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Total_avec_remise'); ?></li>
		<li><?php echo(round($totalremise, 2)); ?> <?php echo $devise->symbole; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Frais_transport'); ?></li>
		<li><?php echo(round($port, 2)); ?> <?php echo $devise->symbole; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Total'); ?></li>
		<li><?php echo(round($totalremise + $port, 2)); ?> <?php echo $devise->symbole; ?></li>
	</ul>
</div>



<?php
	$adr = new Venteadr();
	$adr->charger($commande->adrfact);

	$nompays = new Paysdesc();
	$nompays->charger($adr->pays);
?>
<div class="bordure_bottom" style="margin:0 0 10px 0;">
<div class="entete_liste_client">
	<div class="titre"><?php echo trad('ADRESSE_FACTURATION'); ?></div>
</div>
<ul class="ligne_claire_BlocDescription" style="background-image: url(gfx/degrade_ligne1.png); background-repeat: repeat-x;">
	<li class="designation" style="width:290px; background-image: url(gfx/degrade_ligne1.png); background-repeat: repeat-x;"><?php echo trad('Societe'); ?></li>
	<li><?php echo $adr->entreprise; ?></li>
</ul>
<ul class="ligne_fonce_BlocDescription">
	<li class="designation" style="width:290px;"><?php echo trad('Prenom'); ?></li>
	<li><?php echo $adr->prenom; ?></li>
</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Nom'); ?></li>
		<li><?php echo $adr->nom; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Adresse'); ?></li>
		<li><?php echo $adr->adresse1;?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Adressesuite'); ?></li>
		<li><?php echo $adr->adresse2; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Complement_adresse'); ?></li>
		<li><?php echo $adr->adresse3; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('CP'); ?></li>
		<li><?php echo $adr->cpostal; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Ville'); ?></li>
		<li><?php echo $adr->ville; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Pays'); ?></li>
		<li><?php echo $nompays->titre; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Telephone'); ?></li>
		<li><?php echo $adr->tel; ?></li>
	</ul>
</div>

<?php

	$adr = new Venteadr();
	$adr->charger($commande->adrlivr);

	$nompays = new Paysdesc();
	$nompays->charger($adr->pays);
?>
<div class="bordure_bottom" style="margin:0 0 10px 0;">
<div class="entete_liste_client">
	<div class="titre"><?php echo trad('ADRESSE_LIVRAISON'); ?></div>
</div>
	<ul class="ligne_claire_BlocDescription" style="background-image: url(gfx/degrade_ligne1.png); background-repeat: repeat-x;">
		<li class="designation" style="width:290px; background-image: url(gfx/degrade_ligne1.png); background-repeat: repeat-x;">Société</li>
		<li><?php echo $adr->entreprise; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Prenom'); ?></li>
		<li><?php echo $adr->prenom; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Nom'); ?></li>
		<li><?php echo $adr->nom; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Adresse'); ?></li>
		<li><?php echo $adr->adresse1;?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Adressesuite'); ?></li>
		<li><?php echo $adr->adresse2; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Complement_adresse'); ?></li>
		<li><?php echo $adr->adresse3; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('CP'); ?></li>
		<li><?php echo $adr->cpostal; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Ville'); ?></li>
		<li><?php echo $adr->ville; ?></li>
	</ul>
	<ul class="ligne_fonce_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Pays'); ?></li>
		<li><?php echo $nompays->titre; ?></li>
	</ul>
	<ul class="ligne_claire_BlocDescription">
		<li class="designation" style="width:290px;"><?php echo trad('Telephone'); ?></li>
		<li><?php echo $adr->tel; ?></li>
	</ul>
</div>

<?php
	ActionsAdminModules::instance()->inclure_module_admin("commandedetails");
?>

</div>
<!-- fin du bloc description -->
<!-- bloc colonne de droite -->
<div id="bloc_colonne_droite">
	<div class="entete_client">
		<div class="titre"><?php echo trad('STATUT_REGLEMENT'); ?></div>
		<div class="statut">
      		<form action="<?php echo($_SERVER['PHP_SELF']); ?>" name="formchange" method="post">
                  <input type="hidden" name="ref" value="<?php echo($ref); ?>" />
                  <select name="statutch" id="statutch" onchange="formchange.submit()" class="form">
                    <?php
                	$statut = new Statut();
                	$query = "select * from $statut->table where id<>5";
                	$resul = mysql_query($query);
                	while($row = mysql_fetch_object($resul)){
                		$statutcurdes = new Statutdesc();
                		$statutcurdes->charger($row->id);
                		if($row->id == $statutdesc->statut) $selected="selected"; else $selected="";
                ?>
                    <option value="<?php echo($row->id); ?>" <?php echo($selected); ?>>
                    <?php echo($statutcurdes->titre); ?>
                    </option>
                    <?php

                	}

                ?>
                  </select>
           </form>
     	</div>
	</div>
	<!-- fin du bloc statuts -->
	<div class="entete_client" style="margin:10px 0 0 0;">
		<div class="titre"><?php echo trad('SUIVI_COLIS'); ?></div>
	</div>
	<ul class="claire">
		<li class="designation"><?php echo trad('Num_colis'); ?></li>
		<li><form action="<?php echo($_SERVER['PHP_SELF']); ?>" name="formcolis" method="post">
	               <input type="hidden" name="ref" value="<?php echo($ref); ?>" />
					<input type="text" name="colis" value="<?php echo htmlspecialchars($commande->colis) ?>" /> <input type="submit" value="Valider" />

	             </form>
	    </li>
	</ul>
	<div class="entete_client" style="margin:10px 0 0 0;">
		<div class="titre"><?php echo trad('DOCUMENTS_PDF'); ?></div>
	</div>
	<ul class="claire">
		<li class="designation"><?php echo trad('Facture'); ?></li>
		<li><a href="../client/pdf/facture.php?ref=<?php echo($commande->ref); ?>" target="_blank"><?php echo trad('Visualiser_format_PDF'); ?></a></li>
	</ul>
	<ul class="fonce">
		<li class="designation"><?php echo trad('Bon_livraison'); ?></li>
		<li><a href="livraison.php?ref=<?php echo($commande->ref); ?>" target="_blank"><?php echo trad('Visualiser_format_PDF'); ?></a></li>
	</ul>
	<!-- fin du bloc pdfs -->
</div>
<!-- fin du bloc colonne de droite -->

   </div>
   <?php require_once("pied.php");?>
</div>
</div>

</body>
</html>
